package org.lql.chaos.kafka.example.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: liangqinglong
 * @date: 2025-08-10 03:31
 * @description:
 **/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Order extends BaseMessage {

	private String orderId;

	private String orderName;

	private BigDecimal orderPrice;

	private int orderNum;

	private Timestamp orderTime;

	private String orderStatus;

	private List<OrderItem> orderItems;

	// 静态mock方法，生成测试用的Order对象
	public static Order mock() {
		OrderItem item1 = OrderItem.builder()
				.spuId(1001L)
				.skuId(2001L)
				.orderItemPrice(new BigDecimal("99.99"))
				.orderItemNum(2)
				.build();

		OrderItem item2 = OrderItem.builder()
				.spuId(1002L)
				.skuId(2002L)
				.orderItemPrice(new BigDecimal("49.99"))
				.orderItemNum(1)
				.build();

		List<OrderItem> items = new ArrayList<>();
		items.add(item1);
		items.add(item2);

		BigDecimal totalPrice = items.stream()
				.map(i -> i.getOrderItemPrice().multiply(BigDecimal.valueOf(i.getOrderItemNum())))
				.reduce(BigDecimal.ZERO, BigDecimal::add);

		return Order.builder()
				.orderId("ORD" + System.currentTimeMillis())
				.orderName("示例订单")
				.orderPrice(totalPrice)
				.orderNum(items.stream().mapToInt(OrderItem::getOrderItemNum).sum())
				.orderTime(new Timestamp(System.currentTimeMillis()))
				.orderStatus("待支付")
				.orderItems(items)
				.build();
	}

}
